﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OAuth2
{
    #region 1.0 使用用户名、密码获取Access Token
    /// <summary>
    /// 0.0 AccessTokenModel
    ///https://secure.dhgate.com/dop/oauth2/access_token? grant_type=password& username=jim00213& password=jimkylo025u& client_id=3wSk8Ta3Eo7ReX8SVyrN& client_secret=u8tuAIxYAT1BJ9LmdUwIP2UhcGZXAOO6& scope=basic
    /// </summary>
    class AccessTokenModel
    {
        /// <summary>
        /// 1.0 getAccessTokenModel
        /// </summary>
        public RequestAccessTokenModel RequestAccessToken { get; set; }

        /// <summary>
        /// 2.0 setAccessTokenModel
        /// </summary>
        public ResponeAccessTokenModel ResponeAccessToken { get; set; }
    }

    /// <summary>
    /// 1.0 AccessTokenModel请求
    /// </summary>
    class RequestAccessTokenModel
    {
        /// <summary>
        /// 1.0 固定为 password
        /// </summary>
        private string grant_type="password";

        public string GrantType
        {
            get { return grant_type; }
            set { grant_type = value; }
        }
        
        

        /// <summary>
        /// 2.0 DHgate UserName
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 3.0 DHgate PassWord
        /// </summary>
        public string PassWord { get; set; }

        /// <summary>
        /// 4.0 应用的App Key
        /// </summary>
        public string ClientID { get; set; }

        /// <summary>
        /// 5.0 应用的App Secret
        /// </summary>
        public string ClientSecret { get; set; }

        /// <summary>
        /// 6.0 以空格分隔的权限列表，目前仅支持basic权限
        /// </summary>
        private string scope = "basic";

        public string Scope
        {
            get { return scope; }
            set { scope = value; }
        }

    }

    /// <summary>
    /// 2.0 AccessTokenModel返回
    /// </summary>
    class ResponeAccessTokenModel
    {
        /// <summary>
        /// 1.0 要获取的Access Token
        /// </summary>
        public string AccessToken { get; set; }

        /// <summary>
        /// 2.0 Access Token的有效期，以毫秒为单位
        /// </summary>
        public string ExpiresIn { get; set; }

        /// <summary>
        /// 3.0 用于刷新Access Token 的 Refresh Token,并不是所有应用都会返回该参数
        /// </summary>
        public string RefreshToken { get; set; }

        /// <summary>
        /// 4.0 Access Token最终的访问范围，即用户实际授予的权限列表
        /// </summary>
        public string Scope { get; set; }
    } 
    #endregion

    #region 2.0 使用Refresh Token 刷新 Access Token

    /// <summary>
    /// 0.0 RefreshAccessTokenModel 
    /// https://secure.dhgate.com/dop/oauth2/access_token? grant_type=refresh_token& refresh_token=4pVLNUVS3REGaIdnqCaeObPzF3TYAJRJGvtMqXJQ& client_id=mnKJ01LP3M& client_secret=50aba8b04d19472e89e7ca933e25f171& scope=basic
    /// </summary>
    class RefreshAccessTokenModel
    {
        /// <summary>
        /// 1.0 AccessTokenModel刷新请求
        /// </summary>
        public RequestRefreshAccessTokenModel RequestAccessToken { get; set; }

        /// <summary>
        /// 2.0 AccessTokenModel刷新返回
        /// </summary>
        public ResponeRefreshAccessTokenModel ResponeAccessToken { get; set; }

    }

    /// <summary>
    /// Refresh Token 刷新
    /// </summary>
    class RequestRefreshAccessTokenModel
    {
        /// <summary>
        /// 1.0 必须为“refresh_token” 默认为 refresh_token
        /// </summary>
        private string grant_type = "refresh_token";

        public string GrantType
        {
            get { return grant_type; }
            set { grant_type = value; }
        }

        /// <summary>
        /// 2.0 用于刷新Access Token用的Refresh Token
        /// </summary>
        public string RefreshToken { get; set; }

        /// <summary>
        /// 3.0 应用的App Key
        /// </summary>
        public string ClientID { get; set; }

        /// <summary>
        /// 4.0 应用的App Secret
        /// </summary>
        public string ClientSecret { get; set; }

        /// <summary>
        /// 5.0 以空格分隔的权限列表，若不传递此参数，代表请求默认的basic权限.可省
        /// </summary>
        private string scope = "basic";

        public string Scope
        {
            get { return scope; }
            set { scope = value; }
        }

    }

    /// <summary>
    /// Refresh Token 返回
    /// </summary>
    class ResponeRefreshAccessTokenModel
    {
        public string AccessToken { get; set; }

        public string ExpiresIn { get; set; }

        private string scope = "basic";

        public string Scope
        {
            get { return scope; }
            set { scope = value; }
        }

        public string RefreshToken { get; set; }
    } 
    #endregion
}
